package com.aaa.config;

import com.aaa.dao.UsersDao;
import com.aaa.entity.Users;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Component
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    UsersDao usersDao;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Users user = usersDao.selectByZm(username);
        if (user==null){
            throw new UsernameNotFoundException("用户名不存在");
        }
//        List<String> permits=menuService.selectPermit(user.getId());
//        System.out.println(permits);
        List<GrantedAuthority> authorities=new ArrayList<GrantedAuthority>();
//        for (String permit :permits){
//            authorities.add(new SimpleGrantedAuthority(permit));
//        }
        //去数据库吧用户的权限信息查询出来  往authorities 这个里面放
        // authorities.add(new SimpleGrantedAuthority("role"));
        user.setAuthorities(authorities);
        return user;
    }
}
